<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>练习</title>
    <script src="https://cdn.staticfile.org/react/16.4.0/umd/react.development.js"></script>
    <script src="https://cdn.staticfile.org/react-dom/16.4.0/umd/react-dom.development.js"></script>
    <script src="https://cdn.staticfile.org/babel-standalone/6.26.0/babel.min.js"></script>
</head>

<body>
    <div id="root"></div>
    <div id="root2"></div>
    <div id="root3"></div>
    <script type="text/babel">
        class Counter extends React.Component {
            price = 1188
            state = {
                count: 1,
                totalPrice: 0
            }
            _countAdd = () => {
                this.setState({ count: ++this.state.count })
                this.setState({ totalPrice: this.state.count * this.price })

            }
            _countSub = () => {
                this.setState({ count: --this.state.count })
                this.setState({ totalPrice: this.state.count * this.price })

            }
            render() {
                return (
                    <div>
                        <h3>计数器</h3>
                        <div>
                            <div>单价: {this.price}</div>
                            <div>
                                <button
                                    onClick={this._countSub}
                                    disabled={this.state.count == 1}>
                                    -</button>
                                {this.state.count}
                                <button onClick={this._countAdd}>+</button>
                            </div>
                            <div>
                                总价: {this.state.totalPrice}
                            </div>
                        </div>
                    </div>
                )
            }
        }

        ReactDOM.render(<Counter />, root)
    </script>
</body>

</html>